package com.example.signtime.controller;


import com.example.common.bean.ApiResult;
import com.example.signtime.service.SignTimeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/api")
public class SignTimeController {
     @Autowired
     private SignTimeService signTimeService;

     @ApiOperation("签到")
     @GetMapping("/signIn/{userId}")
     public ModelAndView signIn(@ApiParam(value = "用户Id",required = true)@PathVariable("userId") Integer userId){
          ModelAndView modelAndView = new ModelAndView();
          modelAndView.setViewName("look");
          modelAndView.addObject("result",signTimeService.signIn(userId));
         return modelAndView;
     }

     @ApiOperation("获取签到详情")
     @GetMapping("/{id}")
     public ApiResult getSignDetial(@ApiParam(value = "签到id",required = true)@RequestParam("id") Integer id){
          return signTimeService.getSign(id);
     }

     @ApiOperation("签到列表,1--一周内，2--两周内，3--一个月内")
     @GetMapping("/getSignList")
     public ApiResult getSignList(@ApiParam("统计的签到天数") @RequestParam("countDays") Integer countDays){
          return signTimeService.getSignList(countDays);
     }

     @ApiOperation("本周内的签到记录")
     @GetMapping("/getSignRecords")
     public ModelAndView getSignRecord(@ApiParam(value = "用户id",required = true)@RequestParam("userId") Integer usrId){
          ModelAndView modelAndView = new ModelAndView();
          modelAndView.setViewName("list");
          modelAndView.addObject("SignRecordsVO",signTimeService.getSignRecord(usrId));
          return modelAndView;
     }
}
